import {
	Dialog
} from 'vant';
var Utils = function() {

};

Utils.prototype.deepCopy = function(obj) {
	let _obj = JSON.stringify(obj),
		objClone = JSON.parse(_obj);
	return objClone
}

Utils.prototype.endsWith = function(text, endString) {
	if (text == undefined) return false;
	return text.substring(text.length - endString.length, text.length) === endString;
}

Utils.prototype.startWith = function(text, startString) {
	if (text == undefined) return false;
	return text.substring(0, startString.length) === startString;
}

Utils.prototype.getPageComponent = function(component) {
	var pageComponent = component.$parent;
	while (pageComponent.componentModel == undefined || (pageComponent.componentModel.type != "page" &&
			pageComponent.componentModel.type != "dialog")) {
		pageComponent = pageComponent.$parent;
	}
	return pageComponent;
}

Utils.prototype.getTableComponent = function(component) {
	var pageComponent = component.$parent;
	while (pageComponent.componentModel == undefined || (pageComponent.componentModel.type != "table")) {
		pageComponent = pageComponent.$parent;
	}
	return pageComponent;
}

Utils.prototype.removeArrayElement = function(array, element) {
	var index = -1;
	for (var i = 0; i < array.length; i++) {
		if (array[i] == element) {
			index = i;
		}
	}
	if (index > -1) {
		array.splice(index, 1);
	}
}

Utils.prototype.showMessageDialog = function(scope,title, message) {
	var uiFramework = window.localStorage.getItem("uiframework");
	if (uiFramework == "elementvue3") {
		scope.$alert(message, title);
	} else if (uiFramework == "vantvue3") {
		Dialog.alert({
			title: title,
			message: message,
		}).then(() => {

		});
	}
}
export default new Utils();
